
export default class MobxStore {
    constructor() {
        setTimeout(()=>{
            for(let key in this){
                if(this[key] instanceof MobxStore && key !== "PARENT" && key !== "ROOT"){
                    this[key].PARENT = this;
                    this[key].ROOT = this._findRootStore() || this;
                }
            }
        },0);
    }

    getParentStore = ()=>{
        return new Promise(resolve => {
            setTimeout(()=> resolve(this.PARENT ),0)
        })
    };

    getRootStore = ()=>{
        return new Promise(resolve => {
            setTimeout(()=> resolve(this.ROOT ),0)
        })
    };

    _findRootStore = ()=>{
        let root = this.PARENT;
        let juge = root;
        while (juge){
            if(juge){
                root = juge
            }
            juge = juge.PARENT;
        }
        return root;
    }
}
